#字典性能
import timeit
import random
#字典和列表包含操作时间比较
for i in range(10000, 1000001, 20000):
    t = timeit.Timer("random.randrange({}) in x".format(i), "from __main__ import random, x")
    x = list(range(i))
    lst_time = t.timeit(number = 1000)
    x = {j:None for j in range(i)}
    d_time = t.timeit(number = 1000)
    print("{}, {}, {}".format(i, lst_time, d_time))

#结果
# 10000, 0.08544855472609925, 0.000958736013672023
# 30000, 0.17439335646668042, 0.000979263107183214
# 50000, 0.2784590793899042, 0.000857911760249408
# 70000, 0.3916699243363837, 0.0009569248004481778
# 90000, 0.5205722229184175, 0.0012735854033962823
# ......
# 910000, 5.131937591598216, 0.001563681534207717
# 930000, 5.199991245798628, 0.0012032499225824722
# 950000, 5.490410677711225, 0.0012107966476833099
# 970000, 5.545781908687786, 0.0012189471108285943
# 990000, 5.70264663665057, 0.0011860433869514964